package com.hsy.linemoney.apiservice;

import com.deparse.dpframe.tools.utils.DPGsonUtil;
import com.hsy.linemoney.R;
import com.hsy.linemoney.requests.RequestTask;
import com.hsy.linemoney.utils.ToastUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * 业务相关
 * Created by MartinKent on 2016/9/18.
 */
public class BusinessService extends BasicService<JSONArray> {
//    创建兑换订单
    public void createOrder(JSONObject params, final Callback<OrderCreateResult> callback) {
        String api = "/LmBusinessServices-portlet.order/create-order";
        invoke(0, api, params, new Callback<JSONArray>() {
            @Override
            public void onSuccess(int what, JSONArray result) {
                if (null != callback) {
                    try {
                        callback.onSuccess(0, DPGsonUtil.fromJson(result.get(0).toString(), OrderCreateResult.class));
                    } catch (JSONException e) {
                        e.printStackTrace();
                        callback.onError(what, 0, e.getLocalizedMessage(), e);
                    }
                }
            }

            @Override
            public void onError(int what, int type, String msg, Exception e) {
                if (e instanceof RequestTask.StatusCodeException) {
                    if ("100330".equals(((RequestTask.StatusCodeException) e).getCode())) {
                        ToastUtil.showToast(((RequestTask.StatusCodeException) e).getCode() + "------" + "汇款金额超过1000美元,请先做身份证件验证");
                    } else {
                        ToastUtil.showToast(((RequestTask.StatusCodeException) e).getCode() + "------" + msg);
                    }
                } else {
                    ToastUtil.showToast(R.string.txt_network_failure);
                }
                if (null != callback) {
                    callback.onError(what, 0, e.getLocalizedMessage(), e);
                }
            }
        });
    }

//    创建投标订单
    public void createBidOrder(final JSONObject params, final Callback<BidOrderCreateResult> callback) {
//        String api = "/LmBusinessServices-portlet.order/create-bid-orders";
        String api = "/LmBusinessServices-portlet.bid/confirm-bid-orders";
        invoke(0, api, params, new Callback<JSONArray>() {
            @Override
            public void onSuccess(int what, JSONArray result) {
                if (null != callback) {
                    try {
                        callback.onSuccess(0, DPGsonUtil.fromJson(result.get(0).toString(), BidOrderCreateResult.class));
                    } catch (JSONException e) {
                        e.printStackTrace();
                        callback.onError(what, 0, e.getLocalizedMessage(), e);
                    }
                }
            }

            @Override
            public void onError(int what, int type, String msg, Exception e) {
                if (e instanceof RequestTask.StatusCodeException) {
                    ToastUtil.showToast(((RequestTask.StatusCodeException) e).getCode() + "------" + msg);
                } else {
                    ToastUtil.showToast(R.string.txt_network_failure);
                }
                if (null != callback) {
                    callback.onError(what, 0, e.getLocalizedMessage(), e);
                }
            }
        });
    }

    public static class OrderCreateResult {
        private Status status;

        private Value value;

        public static class Status {
            private String message;

            private String code;

            public void setMessage(String message) {
                this.message = message;
            }

            public String getMessage() {
                return this.message;
            }

            public void setCode(String code) {
                this.code = code;
            }

            public String getCode() {
                return this.code;
            }

        }

        public void setStatus(Status status) {
            this.status = status;
        }

        public Status getStatus() {
            return this.status;
        }

        public void setValue(Value value) {
            this.value = value;
        }

        public Value getValue() {
            return this.value;
        }

        public static class Value {
            private String toLmBankAccountIdString;

            private String durationTypeCd;

            private String serviceFee;

            private String processStatusCd;

            private String toCountryCd;

            private String fromAmount;

            private String fxTypeCd;

            private String orderTime;

            private String serviceTypeCd;

            private String fxRate;

            private String recurringTypeCd;

            private String toAccountId;

            private String fromCountryCd;

            private String processTime;

            private String userId;

            private String toCurrencyCd;

            private String serviceTypeDesc;

            private String fromCurrencyCd;

            private String fromAccountId;

            private String orderId;

            public void setToLmBankAccountIdString(String toLmBankAccountIdString) {
                this.toLmBankAccountIdString = toLmBankAccountIdString;
            }

            public String getToLmBankAccountIdString() {
                return this.toLmBankAccountIdString;
            }

            public void setDurationTypeCd(String durationTypeCd) {
                this.durationTypeCd = durationTypeCd;
            }

            public String getDurationTypeCd() {
                return this.durationTypeCd;
            }

            public void setServiceFee(String serviceFee) {
                this.serviceFee = serviceFee;
            }

            public String getServiceFee() {
                return this.serviceFee;
            }

            public void setProcessStatusCd(String processStatusCd) {
                this.processStatusCd = processStatusCd;
            }

            public String getProcessStatusCd() {
                return this.processStatusCd;
            }

            public void setToCountryCd(String toCountryCd) {
                this.toCountryCd = toCountryCd;
            }

            public String getToCountryCd() {
                return this.toCountryCd;
            }

            public void setFromAmount(String fromAmount) {
                this.fromAmount = fromAmount;
            }

            public String getFromAmount() {
                return this.fromAmount;
            }

            public void setFxTypeCd(String fxTypeCd) {
                this.fxTypeCd = fxTypeCd;
            }

            public String getFxTypeCd() {
                return this.fxTypeCd;
            }

            public void setOrderTime(String orderTime) {
                this.orderTime = orderTime;
            }

            public String getOrderTime() {
                return this.orderTime;
            }

            public void setServiceTypeCd(String serviceTypeCd) {
                this.serviceTypeCd = serviceTypeCd;
            }

            public String getServiceTypeCd() {
                return this.serviceTypeCd;
            }

            public void setFxRate(String fxRate) {
                this.fxRate = fxRate;
            }

            public String getFxRate() {
                return this.fxRate;
            }

            public void setRecurringTypeCd(String recurringTypeCd) {
                this.recurringTypeCd = recurringTypeCd;
            }

            public String getRecurringTypeCd() {
                return this.recurringTypeCd;
            }

            public void setToAccountId(String toAccountId) {
                this.toAccountId = toAccountId;
            }

            public String getToAccountId() {
                return this.toAccountId;
            }

            public void setFromCountryCd(String fromCountryCd) {
                this.fromCountryCd = fromCountryCd;
            }

            public String getFromCountryCd() {
                return this.fromCountryCd;
            }

            public void setProcessTime(String processTime) {
                this.processTime = processTime;
            }

            public String getProcessTime() {
                return this.processTime;
            }

            public void setUserId(String userId) {
                this.userId = userId;
            }

            public String getUserId() {
                return this.userId;
            }

            public void setToCurrencyCd(String toCurrencyCd) {
                this.toCurrencyCd = toCurrencyCd;
            }

            public String getToCurrencyCd() {
                return this.toCurrencyCd;
            }

            public void setServiceTypeDesc(String serviceTypeDesc) {
                this.serviceTypeDesc = serviceTypeDesc;
            }

            public String getServiceTypeDesc() {
                return this.serviceTypeDesc;
            }

            public void setFromCurrencyCd(String fromCurrencyCd) {
                this.fromCurrencyCd = fromCurrencyCd;
            }

            public String getFromCurrencyCd() {
                return this.fromCurrencyCd;
            }

            public void setFromAccountId(String fromAccountId) {
                this.fromAccountId = fromAccountId;
            }

            public String getFromAccountId() {
                return this.fromAccountId;
            }

            public void setOrderId(String orderId) {
                this.orderId = orderId;
            }

            public String getOrderId() {
                return this.orderId;
            }

        }
    }

    public static class BidOrderCreateResultNo {
        private Status status;

        private Value value;

        public Status getStatus() {
            return status;
        }

        public void setStatus(Status status) {
            this.status = status;
        }

        public Value getValue() {
            return value;
        }

        public void setValue(Value value) {
            this.value = value;
        }

        public static class Status {
            private String message;

            private String code;

            public void setMessage(String message) {
                this.message = message;
            }

            public String getMessage() {
                return this.message;
            }

            public void setCode(String code) {
                this.code = code;
            }

            public String getCode() {
                return this.code;
            }

        }

        public static class Value {

            private String toLmBankAccountIdString;

            private String durationTypeCd;

            private String recurringTypeCd;

            private List<BidOrders> bidOrders;

            private String toAccountId;

            private String parentOrderId;

            private String redirectURL;

            private String toCurrencyCd;

            private String userId;

            private String fromCurrencyCd;

            private String fromAccountId;

            public void setToLmBankAccountIdString(String toLmBankAccountIdString) {
                this.toLmBankAccountIdString = toLmBankAccountIdString;
            }

            public String getToLmBankAccountIdString() {
                return this.toLmBankAccountIdString;
            }

            public void setDurationTypeCd(String durationTypeCd) {
                this.durationTypeCd = durationTypeCd;
            }

            public String getDurationTypeCd() {
                return this.durationTypeCd;
            }

            public void setRecurringTypeCd(String recurringTypeCd) {
                this.recurringTypeCd = recurringTypeCd;
            }

            public String getRecurringTypeCd() {
                return this.recurringTypeCd;
            }

            public void setBidOrders(List<BidOrders> bidOrders) {
                this.bidOrders = bidOrders;
            }

            public List<BidOrders> getBidOrders() {
                return this.bidOrders;
            }

            public void setToAccountId(String toAccountId) {
                this.toAccountId = toAccountId;
            }

            public String getToAccountId() {
                return this.toAccountId;
            }

            public void setParentOrderId(String parentOrderId) {
                this.parentOrderId = parentOrderId;
            }

            public String getParentOrderId() {
                return this.parentOrderId;
            }

            public void setRedirectURL(String redirectURL) {
                this.redirectURL = redirectURL;
            }

            public String getRedirectURL() {
                return this.redirectURL;
            }

            public void setToCurrencyCd(String toCurrencyCd) {
                this.toCurrencyCd = toCurrencyCd;
            }

            public String getToCurrencyCd() {
                return this.toCurrencyCd;
            }

            public void setUserId(String userId) {
                this.userId = userId;
            }

            public String getUserId() {
                return this.userId;
            }

            public void setFromCurrencyCd(String fromCurrencyCd) {
                this.fromCurrencyCd = fromCurrencyCd;
            }

            public String getFromCurrencyCd() {
                return this.fromCurrencyCd;
            }

            public void setFromAccountId(String fromAccountId) {
                this.fromAccountId = fromAccountId;
            }

            public String getFromAccountId() {
                return this.fromAccountId;
            }
        }

        public static class BidOrders {
            private String bidAmount;

            private String bidStatus;

            private String bidRate;

            private String bidOrderId;

            private String hostOrderId;

            public void setBidAmount(String bidAmount) {
                this.bidAmount = bidAmount;
            }

            public String getBidAmount() {
                return this.bidAmount;
            }

            public void setBidStatus(String bidStatus) {
                this.bidStatus = bidStatus;
            }

            public String getBidStatus() {
                return this.bidStatus;
            }

            public void setBidRate(String bidRate) {
                this.bidRate = bidRate;
            }

            public String getBidRate() {
                return this.bidRate;
            }

            public void setBidOrderId(String bidOrderId) {
                this.bidOrderId = bidOrderId;
            }

            public String getBidOrderId() {
                return this.bidOrderId;
            }

            public void setHostOrderId(String hostOrderId) {
                this.hostOrderId = hostOrderId;
            }

            public String getHostOrderId() {
                return this.hostOrderId;
            }
        }
    }

    public static class BidOrderCreateResult{
        private Value value;

        private Status status;

        public void setValue(Value value){
            this.value = value;
        }
        public Value getValue(){
            return this.value;
        }
        public void setStatus(Status status){
            this.status = status;
        }
        public Status getStatus(){
            return this.status;
        }

        public class Value {
            private String durationTypeCd;

            private double serviceFee;

            private String processStatusCd;

            private int fromAmount;

            private String toCountryCd;

            private String fxTypeCd;

            private String serviceTypeCd;

            private String orderTime;

            private int fxRate;

            private String recurringTypeCd;

            private String toLmBankAccountIdString;

            private String fromCountryCd;

            private long toAccountId;

            private String toCurrencyCd;

            private int userId;

            private String processTime;

            private String serviceTypeDesc;

            private String fromCurrencyCd;

            private int fromAccountId;

            private long orderId;

            public void setDurationTypeCd(String durationTypeCd){
                this.durationTypeCd = durationTypeCd;
            }
            public String getDurationTypeCd(){
                return this.durationTypeCd;
            }
            public void setServiceFee(double serviceFee){
                this.serviceFee = serviceFee;
            }
            public double getServiceFee(){
                return this.serviceFee;
            }
            public void setProcessStatusCd(String processStatusCd){
                this.processStatusCd = processStatusCd;
            }
            public String getProcessStatusCd(){
                return this.processStatusCd;
            }
            public void setFromAmount(int fromAmount){
                this.fromAmount = fromAmount;
            }
            public int getFromAmount(){
                return this.fromAmount;
            }
            public void setToCountryCd(String toCountryCd){
                this.toCountryCd = toCountryCd;
            }
            public String getToCountryCd(){
                return this.toCountryCd;
            }
            public void setFxTypeCd(String fxTypeCd){
                this.fxTypeCd = fxTypeCd;
            }
            public String getFxTypeCd(){
                return this.fxTypeCd;
            }
            public void setServiceTypeCd(String serviceTypeCd){
                this.serviceTypeCd = serviceTypeCd;
            }
            public String getServiceTypeCd(){
                return this.serviceTypeCd;
            }
            public void setOrderTime(String orderTime){
                this.orderTime = orderTime;
            }
            public String getOrderTime(){
                return this.orderTime;
            }
            public void setFxRate(int fxRate){
                this.fxRate = fxRate;
            }
            public int getFxRate(){
                return this.fxRate;
            }
            public void setRecurringTypeCd(String recurringTypeCd){
                this.recurringTypeCd = recurringTypeCd;
            }
            public String getRecurringTypeCd(){
                return this.recurringTypeCd;
            }
            public void setToLmBankAccountIdString(String toLmBankAccountIdString){
                this.toLmBankAccountIdString = toLmBankAccountIdString;
            }
            public String getToLmBankAccountIdString(){
                return this.toLmBankAccountIdString;
            }
            public void setFromCountryCd(String fromCountryCd){
                this.fromCountryCd = fromCountryCd;
            }
            public String getFromCountryCd(){
                return this.fromCountryCd;
            }
            public void setToAccountId(long toAccountId){
                this.toAccountId = toAccountId;
            }
            public long getToAccountId(){
                return this.toAccountId;
            }
            public void setToCurrencyCd(String toCurrencyCd){
                this.toCurrencyCd = toCurrencyCd;
            }
            public String getToCurrencyCd(){
                return this.toCurrencyCd;
            }
            public void setUserId(int userId){
                this.userId = userId;
            }
            public int getUserId(){
                return this.userId;
            }
            public void setProcessTime(String processTime){
                this.processTime = processTime;
            }
            public String getProcessTime(){
                return this.processTime;
            }
            public void setServiceTypeDesc(String serviceTypeDesc){
                this.serviceTypeDesc = serviceTypeDesc;
            }
            public String getServiceTypeDesc(){
                return this.serviceTypeDesc;
            }
            public void setFromCurrencyCd(String fromCurrencyCd){
                this.fromCurrencyCd = fromCurrencyCd;
            }
            public String getFromCurrencyCd(){
                return this.fromCurrencyCd;
            }
            public void setFromAccountId(int fromAccountId){
                this.fromAccountId = fromAccountId;
            }
            public int getFromAccountId(){
                return this.fromAccountId;
            }
            public void setOrderId(long orderId){
                this.orderId = orderId;
            }
            public long getOrderId(){
                return this.orderId;
            }

        }

        public class Status {
            private String message;

            private String code;

            public void setMessage(String message){
                this.message = message;
            }
            public String getMessage(){
                return this.message;
            }
            public void setCode(String code){
                this.code = code;
            }
            public String getCode(){
                return this.code;
            }

        }

    }
}
